package com.sdgakj.repository;

import com.sdgakj.entity.ShtDistrict;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ShtDistrictDao extends PagingAndSortingRepository<ShtDistrict, Integer>, JpaSpecificationExecutor<ShtDistrict> {

    /**
     * 根据车牌号查询车载信息
     * 
     * @param province
     * @param district
     * @return
     */
    @Query("from ShtDistrict d where d.province.name = :province AND d.city.name = :city AND d.name = :district ")
    ShtDistrict findByNames(@Param("province") String province, @Param("city") String city,
            @Param("district") String district);

    @Query(value="select * from sht_districts where id in(select district_id from jcc_detect_factory where city_id=?1)",nativeQuery=true)
    List<ShtDistrict> findDis4Factory(int cid);

    @Query(value="select district_id from jcc_detect_factory where city_id=?1",nativeQuery=true)
    List<Integer> findDisIds4Factory(int cid);
}
